.text
.global xp_asm_memcmp
.type   xp_asm_memcmp,function

/* 
 * int xp_asm_memcmp (const void* p1, const void* p2, xp_size_t n); 
 */

xp_asm_memcmp:
	pushl %esi
	pushl %edi

#	movl 4(%esp), %esi
#	movl 8(%esp), %edi
#	movl 12(%esp), %ecx
	movl 12(%esp), %esi
	movl 16(%esp), %edi
	movl 20(%esp), %ecx
	jecxz xp_asm_memcmp_equal

	movl %ecx, %eax
	andl $1, %eax
	testl %eax, %eax
	je xp_asm_memcmp_cmpsw

	cld
	repz cmpsb 
	je xp_asm_memcmp_equal

xp_asm_memcmp_unequal:
	sbbl %eax, %eax
	orb $1, %al

	popl %edi
	popl %esi
	ret	

xp_asm_memcmp_cmpsw:
	shrl $1, %ecx #	shrl $2, %ecx
	cld
	repz cmpsw    # repz cmpsd
	jne xp_asm_memcmp_unequal

xp_asm_memcmp_equal:
	xorl %eax, %eax
	popl %edi
	popl %esi
	ret	

/*
xp_asm_memcmp:
	pushl %ebp
	movl %esp, %ebp

	movl 8(%ebp), %esi
	movl 12(%ebp), %edi
	movl 16(%ebp), %ecx

	movl %ecx, %eax
	andl $1, %eax
	testl %eax, %eax
	je asm_memcmp_cmpsw

	cld
	repz cmpsb 
	je asm_memcmp_equal

xp_asm_memcmp_unequal:
	sbbl %eax, %eax
	orb $1, %al

	movl %ebp, %esp
	popl %ebp
	ret	

xp_asm_memcmp_cmpsw:
	shrl $1, %ecx
	cld
	repz cmpsw
	jne xp_asm_memcmp_unequal

xp_asm_memcmp_equal:
	xorl %eax, %eax
	movl %ebp, %esp
	popl %ebp
	ret	
*/

/*
xp_asm_memcmp:
	pushl %ebp
	movl %esp, %ebp

	pushl %esi
	pushl %edi

	movl 8(%ebp), %esi
	movl 12(%ebp), %edi
	movl 16(%ebp), %ecx

	cld
	repz cmpsb 
	je asm_memcmp_equal

	sbbl %eax, %eax
	orb $1, %al

	popl %edi
	popl %esi

	movl %ebp, %esp
	popl %ebp
	ret	

xp_asm_memcmp_equal:
	xorl %eax, %eax

	popl %edi
	popl %esi

	movl %ebp, %esp
	popl %ebp
	ret	
*/
